// pages/application/application.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        List: [],
        Parameters:{
            pageParam: {
              orderBy: "id asc",
              pageNum: 1,
              pageSize: 10
            },
            id: 0,
          },
        sessionID:'',
        projectId:""
    },

     // 用于设置总页数
     totalPages: 1,

    
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData({
            ['Parameters.id']: options.id,
            projectId:options.id
        })

        //console.log("storage sessionID:", wx.getStorageSync('sessionID'));
        //从缓存中取出sessionId
        this.setData({
            sessionID:wx.getStorageSync('sessionID')
        })
        console.log(this.data.Parameters)
        // 
        wx.request({
          url: 'https://www.hschuangsai.com/recruitProject/applications/list',
          data: this.data.Parameters,
          method: "POST",
          header: {
            'content-type': 'application/json',
            'session': this.data.sessionID
          },
          success: (result) => {
            console.log("简历",result)
              if(result.data.code == -1){
                  wx.showToast({
                    title: result.data.commonErrorCode.errorSuggestion,
                    icon: 'none'
                  })
              }else{
                  this.totalPages=result.data.data.pages,
                  //console.log("totalPage is:",this.totalPages)
                  this.setData({
                      List: result.data.data.list
                  })
              }
          },
        })
    },
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        this.data.Parameters.pageParam.pageNum+=1;
        if(this.data.Parameters.pageParam.pageNum>this.totalPages){
        //console.log('加载失败')
      }else{
        wx.request({
            url: 'https://www.hschuangsai.com/recruitProject/applications/list',
            data: this.data.Parameters,
            method: "POST",
            header: {
              'content-type': 'application/json',
              'session': this.data.sessionID
            },
            success: (result) => {
                if(result.data.code == -1){
                    wx.showToast({
                      title: result.data.commonErrorCode.errorSuggestion,
                      icon: 'none'
                    })
                }else{
                    this.setData({
                        List: [...this.data.List,...result.data.data.list]
                    })
                }
            },
          })
      }
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})